home *** CD-ROM | disk | FTP | other *** search
- #ifndef powerc
- #include <SetupA4.h>
- #include <A4Stuff.h>
- #endif
-
- #include "ExternalInterface.h"
-
- static Boolean quote_breaks[256];
-
- static void init_quote_breaks(void)
- {
- short i;
-
- for (i = 0; i < 256; i++)
- quote_breaks[i] = FALSE;
-
- quote_breaks['\t'] = TRUE;
- quote_breaks['\r'] = TRUE;
- quote_breaks[0x00CA] = TRUE;
- quote_breaks[' '] = TRUE;
- quote_breaks['('] = TRUE;
- quote_breaks['{'] = TRUE;
- quote_breaks['['] = TRUE;
- quote_breaks[0x00D2] = TRUE;
- quote_breaks[0x00D4] = TRUE;
- }
-
- #ifdef powerc
- unsigned long __procinfo = ExtensionUPPInfo;
- #endif
-
- pascal void main(ExternalCallbackBlock *callbacks, WindowPtr w)
- {
- Handle h;
-
- long i, len;
-
- long saved_a4;
-
- Boolean changed = FALSE;
- register unsigned char c;
- register unsigned char *p;
-
- #ifndef powerc
- saved_a4 = SetCurrentA4();
- #endif
-
- h = CallGetWindowContents(callbacks->GetWindowContents, w);
- len = GetHandleSize(h);
-
- init_quote_breaks();
-
- #ifdef DO_PROGRESS
- CallStartProgress(callbacks->StartProgress, "\pConverting Quotes…", len, FALSE);
- #endif
-
- p = (unsigned char *)*h;
- for (i = 0; i < len; i++)
- {
- #ifdef DO_PROGRESS
- CallDoProgress(callbacks->DoProgress, i);
- #endif
- c = *p;
-
- if ((i == 0) || quote_breaks[p[-1]])
- {
- if (c == '"')
- c = '“';
- else if (c == '\'')
- c = '‘';
- }
- else
- {
- if (c == '"')
- c = '”';
- else if (c == '\'')
- c = '’';
- }
-
- if (c != *p)
- {
- *p = c;
- changed = TRUE;
- }
-
- p++;
- }
-
- #ifdef DO_PROGRESS
- CallDoneProgress(callbacks->DoneProgress);
- #endif
-
- if (changed)
- CallContentsChanged(callbacks->ContentsChanged, w);
-
- #ifndef powerc
- SetA4(saved_a4);
- #endif
- }
-